<style>
    .ibox {
        clear: both;
        margin-bottom: 25px;
        margin-top: 0;
        padding: 0;
    }

    .mailbox-content {
        background: 0 0;
        border: none;
        padding: 10px;

    }

    .ibox-content {
        clear: both;
        color: inherit;
    }

    .file-manager {
        list-style: none outside none;
        margin: 0;
        padding: 0;
    }

    .space-25 {
        margin: 25px 0;
    }

    .file-manager h5 {
        text-transform: uppercase;
    }

    .ibox-content h1, .ibox-content h2, .ibox-content h3, .ibox-content h4, .ibox-content h5, .ibox-title h1, .ibox-title h2, .ibox-title h3, .ibox-title h4, .ibox-title h5 {
        margin-top: 5px;
    }

    h5 {
        font-size: 12px;
    }

    .h4, .h5, .h6, h4, h5, h6 {
        margin-top: 10px;
        margin-bottom: 10px;
    }

    .m-b-md {
        margin-bottom: 20px;
    }

    .folder-list li {
        border-bottom: 1px solid #e7eaec;
        display: block;
    }

    .folder-list li a {
        color: #666;
        display: block;
        padding: 8px 0;
    }

    h3, h4, h5 {
        font-weight: 600;
    }

    .folder-list li i {
        margin-right: 7px;
        color: #3d4d5d;
    }

    .badge-warning, .label-warning {
        background-color: #f8ac59;
        color: #FFF;
    }

    .label {
        background-color: #d1dade;
        color: #5e5e5e;
        font-size: 10px;
        font-weight: 600;
        padding: 3px 8px;
        text-shadow: none;
    }

    .pull-right {
        float: right !important;
    }

    ol, ul {
        margin-top: 0;
        margin-bottom: 10px;
    }

    .category-list li {
        display: block;
    }

    .category-list li a {
        color: #666;
        display: block;
        padding: 8px 0;
    }

    .category-list li a .text-navy {
        color: #1ab394;
    }

    .category-list li i {
        margin-right: 8px;
    }

    .file-manager h5.tag-title {
        margin-top: 20px;
    }

    ul.notes li, ul.tag-list li {
        list-style: none;
    }

    .mailbox-content .tag-list li a {
        background: #fff;
    }

    .tag-list li a {
        font-size: 10px;
        background-color: #f3f3f4;
        padding: 5px 12px;
        color: inherit;
        border-radius: 2px;
        border: 1px solid #e7eaec;
        margin-right: 5px;
        margin-top: 5px;
        display: block;
    }

    ul.notes li, ul.tag-list li {
        list-style: none;
    }

    .tag-list li {
        float: left;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-col-xs12 layui-col-md3">
            <div class="ibox float-e-margins">
                <div class="ibox-content mailbox-content">
                    <div class="file-manager">
                        <a class="layui-btn layui-btn-fluid" href="{:url('email/add')}">写信</a>
                        <div class="space-25"></div>
                        <h5>文件夹</h5>
                        <ul class="folder-list m-b-md" style="padding: 0">
                            <li>
                                <a href="#"><i class="layui-icon layui-icon-website"
                                               style="font-size: 12px;"></i>收件箱<span
                                        class="label label-warning pull-right">16</span>
                                </a>
                            </li>
                            <li>
                                <a href="#"><i class="layui-icon layui-icon-website"
                                               style="font-size: 12px;"></i>星标邮件<span
                                        class="label label-warning pull-right">16</span>
                                </a>
                            </li>
                            <li>
                                <a href="#"><i class="layui-icon layui-icon-website"
                                               style="font-size: 12px;"></i>重要<span
                                        class="label label-warning pull-right">16</span>
                                </a>
                            </li>
                            <li>
                                <a href="#"><i class="layui-icon layui-icon-website"
                                               style="font-size: 12px;"></i>草稿<span
                                        class="label label-warning pull-right">16</span>
                                </a>
                            </li>
                            <li>
                                <a href="#"><i class="layui-icon layui-icon-website"
                                               style="font-size: 12px;"></i>垃圾箱<span
                                        class="label label-warning pull-right">16</span>
                                </a>
                            </li>

                        </ul>
                        <h5>分类</h5>
                        <ul class="category-list" style="padding: 0">
                            <li>
                                <a href="#"> <i class="layui-icon layui-icon-circle-dot text-navy"
                                                style="font-size: 12px;"></i> 工作</a>
                            </li>
                            <li>
                                <a href="#"> <i class="layui-icon layui-icon-circle-dot text-navy"
                                                style="font-size: 12px;"></i> 文档</a>
                            </li>
                            <li>
                                <a href="#"> <i class="layui-icon layui-icon-circle-dot text-navy"
                                                style="font-size: 12px;"></i> 广告</a>
                            </li>
                            <li>
                                <a href="#"> <i class="layui-icon layui-icon-circle-dot text-navy"
                                                style="font-size: 12px;"></i> 社交</a>
                            </li>
                        </ul>
                        <h5 class="tag-title">标签</h5>
                        <ul class="tag-list" style="padding: 0">
                            <li><a href="#"><i class="layui-icon layui-icon-note" style="font-size: 12px;"></i> 朋友</a>
                            </li>
                            <li><a href="#"><i class="layui-icon layui-icon-note" style="font-size: 12px;"></i> 工作</a>
                            </li>
                            <li><a href="#"><i class="layui-icon layui-icon-note" style="font-size: 12px;"></i> 家庭</a>
                            </li>
                            <li><a href="#"><i class="layui-icon layui-icon-note" style="font-size: 12px;"></i> 孩子</a>
                            </li>
                            <li><a href="#"><i class="layui-icon layui-icon-note" style="font-size: 12px;"></i> 假期</a>
                            </li>
                            <li><a href="#"><i class="layui-icon layui-icon-note" style="font-size: 12px;"></i> 音乐</a>
                            </li>
                            <li><a href="#"><i class="layui-icon layui-icon-note" style="font-size: 12px;"></i> 照片</a>
                            </li>
                            <li><a href="#"><i class="layui-icon layui-icon-note" style="font-size: 12px;"></i> 电影</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-card-body layui-col-xs12 layui-col-md9">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-admin layui-btn-sm" title="刷新" data-type="refresh"><i
                        class="layui-icon layui-icon-refresh-3"></i>
                </button>
                <button class="layui-btn layuiadmin-btn-admin layui-btn-sm {$auth->check('dictionaries/add')?$auth->check('dictionaries/add'):'hide'}"
                        title="添加" data-type="add"><i
                        class="layui-icon layui-icon-add-1"></i>已读
                </button>
                <button class="layui-btn layuiadmin-btn-admin layui-btn-sm {$auth->check('dictionaries/edit')?$auth->check('dictionaries/edit'):'hide'}"
                        title="编辑" data-type="edit"><i
                        class="layui-icon layui-icon-edit"></i>重要
                </button>
                <button class="layui-btn layuiadmin-btn-admin layui-btn-sm {$auth->check('dictionaries/del')?$auth->check('dictionaries/del'):'hide'}"
                        title="删除" data-type="batchdel"><i
                        class="layui-icon layui-icon-delete"></i>删除
                </button>
            </div>
            <table id="LAY-user-back-manage" lay-filter="LAY-user-back-manage"></table>
        </div>
    </div>
</div>

<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    var listUrl = "{:url('email/index')}", create = "{:url('email/add')}",
        deleteUrl = "{:url('email/del')}", edit = "{:url('email/edit')}", getBody = "{:url('email/getBody')}";
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'soulTable', 'laydate'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table, soulTable = layui.soulTable, laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start_time' //指定元素
            , trigger: 'click'//呼出事件改成click
        });
        laydate.render({
            elem: '#end_time' //指定元素
            , trigger: 'click'//呼出事件改成click
        });
        table.render({
            elem: "#LAY-user-back-manage", url: listUrl
            , overflow: {
                type: 'tips'
                // ,hoverTime: 500 // 悬停时间，单位ms, 悬停 hoverTime 后才会显示，默认为 0
                , color: 'white' // 字体颜色
                , bgColor: '#009688' // 背景色
            }
            , cols: [
                [
                    {type: "checkbox", fixed: "left"},
                    {field: "mid", align: "center", title: "ID", hide: true},
                    {field: "toNameOth", align: "center", title: "发送人"},
                    {field: "subject", align: "center", title: "主题"},
                    {field: "date", align: "center", title: "时间"}
                ]],
            response: {
                statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
            }, done: function (e) {
                soulTable.render(this);
            },
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code,
                    "count": res.total, //解析数据长度
                    "data": res.data, //解析数据列表
                };

            },
            text: {
                none: '呀！一条数据都没有'
            },

            page: false,
            limit: 15,
        });
        //监听行单击事件（双击事件为：rowDouble）
        table.on('row(LAY-user-back-manage)', function (obj) {
            var data = obj.data;
            var param = $.param({'id': data.mid});
            $.ajax({
                url: getBody,
                type: 'post',
                data: param,
                success: function (res) {
                    if (res.code === 200) {
                        layer.open({
                            type: 1,
                            content: res.data,
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5});
                        return false;
                    }
                }
            });

            //标注选中样式
            obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
        });
        //监听搜索
        form.on('submit(LAY-user-back-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('LAY-user-back-manage', {
                where: field
            });
        });
        //事件
        var active = {
            batchdel: function () {
                var checkStatus = table.checkStatus('LAY-user-back-manage')
                    , checkData = checkStatus.data; //得到选中的数据
                if (checkData.length === 0) {
                    return layer.msg('请选择数据');
                }
                var new_arr = [];
                for (var i = 0; i < checkData.length; i++) {
                    new_arr.push({"id": checkData[i].id, 'table': checkData[i].table_name});
                }
                layer.confirm('确定删除吗？', function (index) {
                    //执行 Ajax 后重载
                    $.ajax({
                        url: deleteUrl,
                        type: "post",
                        data: {
                            'object': new_arr
                        },
                        beforeSend: function () {
                            layer.load(2, {
                                shade: [0.6, '#fff'], content: '数据删除中...', success: function (layero) {
                                    layero.find('.layui-layer-content').css({
                                        'padding-top': '6px',
                                        'width': '150px',
                                        'padding-left': '40px'
                                    });
                                    layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                                        'width': '150px !important',
                                        'background-position': '2px 0 !important'
                                    });
                                }
                            });
                        },
                        success: function (res) {
                            if (res.code === 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('LAY-user-back-manage');
                                layer.closeAll(); //关闭弹层
                            } else {
                                layer.msg(res.msg, {icon: 5});
                                return false;
                            }
                        }
                    });
                    // table.reload('LAY-user-back-manage');
                    // layer.msg('已删除');
                });
            }
            , add: function () {
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '添加'
                    , content: create
                    , area: ['50%', '50%']
                    , maxmin: true
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-back-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            if (field.table_name == "") {
                                layer.msg("请选择数据字典类别");
                                return false;
                            }
                            if (field.name == "") {
                                layer.msg("请输入名称");
                                return false;
                            }
                            //提交 Ajax 成功后，静态更新表格中的数据
                            $.ajax({
                                url: create,
                                type: 'post',
                                data: field,
                                beforeSend: function () {
                                    layer.load(2, {
                                        shade: [0.6, '#fff'], content: '数据新增中...', success: function (layero) {
                                            layero.find('.layui-layer-content').css({
                                                'padding-top': '6px',
                                                'width': '150px',
                                                'padding-left': '40px'
                                            });
                                            layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                                                'width': '150px !important',
                                                'background-position': '2px 0 !important'
                                            });
                                        }
                                    });
                                },
                                success: function (res) {
                                    if (res.code === 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('LAY-user-back-manage');
                                        layer.closeAll(); //关闭弹层
                                    } else {

                                        layer.msg(res.msg, {icon: 5});
                                        return false;
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                    }
                });
            },
            refresh: function () {
                table.reload('LAY-user-back-manage');
            },
            edit: function () {
                var checkStatus = table.checkStatus('LAY-user-back-manage')
                    , checkData = checkStatus.data; //得到选中的数据
                if (checkData.length === 0) {
                    return layer.msg('请选择数据');
                }
                if (checkData.length > 1) {
                    return layer.msg('只能选择一条信息');
                }
                var id = '';
                var table_name = '';
                for (var i = 0; i < checkData.length; i++) {
                    id += checkData[i].id + ",";
                    table_name += checkData[i].table_name + ",";
                }
                id = id.substring(0, id.length - 1);
                table_name = table_name.substring(0, table_name.length - 1);
                var param = $.param({'id': id, 'table': table_name});
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '编辑'
                    , content: edit + '?' + param
                    , area: ['50%', '50%']
                    , maxmin: true
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-back-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            if (field.table_name == "") {
                                layer.msg("请选择数据字典类别");
                                return false;
                            }
                            if (field.name == "") {
                                layer.msg("请输入名称");
                                return false;
                            }
                            //提交 Ajax 成功后，静态更新表格中的数据
                            $.ajax({
                                url: edit,
                                type: 'post',
                                data: field,
                                beforeSend: function () {
                                    layer.load(2, {
                                        shade: [0.6, '#fff'], content: '数据新增中...', success: function (layero) {
                                            layero.find('.layui-layer-content').css({
                                                'padding-top': '6px',
                                                'width': '150px',
                                                'padding-left': '40px'
                                            });
                                            layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                                                'width': '150px !important',
                                                'background-position': '2px 0 !important'
                                            });
                                        }
                                    });
                                },
                                success: function (res) {
                                    if (res.code === 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('LAY-user-back-manage');
                                        layer.closeAll(); //关闭弹层
                                    } else {

                                        layer.msg(res.msg, {icon: 5});
                                        return false;
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                    }
                });
            },
            export: function () {
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '导入'
                    , content: uploadExcel
                    , area: ['50%', '50%']
                    , maxmin: true
                });
            }

        };
        $('.layui-btn.layuiadmin-btn-admin').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
